using System.Collections;
using System.Collections.Generic;
using cfg.enemy;
using cfg.wave;
using UnityEngine;

namespace QFramework.Monk
{
    public class WaveSystem : AbstractSystem
    {
        public Dictionary<string,EnemyBase> mEnemyPool;
        private ConfigModel mConfigModel;
        private Queue<Wave> mWaveQueue = new Queue<Wave>();
        public Wave mCurWave;
        public int mCurWaveIndex;
        private float totalWaveTime;//总波次持续的时间
        protected override void OnInit()
        {
            mEnemyPool = DictionaryPool<string,EnemyBase>.Get();
            mConfigModel= this.GetModel<ConfigModel>();
            
            //InitWaveQueue();
        }

        public void InitWaveQueue()
        {
            var waveList = mConfigModel.GetAllWaveConfig();
            mWaveQueue.Clear();
            totalWaveTime = 0;
            foreach (var wave in waveList)
            {
                mWaveQueue.Enqueue(wave);
                totalWaveTime+=wave.Duration;
            }
            
            mCurWaveIndex = 0;
            mCurWave = null;
        }
        
        public Wave GetCurWave()
        {
            return mCurWave;
        }
        
        public  EnemyInfo GetRandomEnemyInfo()
        {
            if (mCurWave!=null)
            {
                return mConfigModel.RandomCreateEnemy(mCurWave);
            }
            return  null;
        }
        
        public void NextWave()
        {
            if (mWaveQueue.Count>0)
            {
                mCurWave = mWaveQueue.Dequeue();
                mCurWaveIndex++;
            }
        }

        public bool IsLastWave()
        {
            return mWaveQueue.Count == 0;
        }

        public bool IsGamePass()
        {
            return  AppStart.curSec.Value>totalWaveTime&&IsLastWave()&&AppStart.enemyNum.Value==0;
        }
        
    }
    
}

